package edu.zut.cs.software.example.Menu.web.spring.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import edu.zut.cs.software.example.Menu.domain.MainMenu;
import edu.zut.cs.software.example.menu.service.MenuManager;

/**
 * Retrieve menu data
 * @author chen ming yang
 *
 */
@RestController
public class MenuController {

	@Autowired
	MenuManager menuManager;

	@RequestMapping("/menus")
	public String getAllMenus() {

		HashMap<String, Object> data = new HashMap<>();
 
		List<MainMenu> menus=menuManager.MenuService();

		if (menus != null) {
			data.put("menus", menus);
			data.put("flag", 200);
		} else {
			data.put("flag", 404);
		}

		return JSON.toJSONString(data,SerializerFeature.DisableCircularReferenceDetect);
	}

}
